package com.zhang.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhang.domain.Permissions;
import com.zhang.domain.Role;
import com.zhang.mapper.RoleMapper;
import com.zhang.query.RoleQuery;
import com.zhang.service.IRoleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zh
 * @create 2022-02-14 9:25
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class RoleServiceImpl implements IRoleService {
    @Resource
    private RoleMapper mapper;
    @Override
    public PageInfo<Role> getAll(RoleQuery rq) {
        PageHelper.startPage(rq.getCurrentPage(),rq.getPageSize());
        List<Role> list = mapper.loadAll(rq);
        Page<Role> page = (Page<Role>) list;
        return page.toPageInfo();
    }
    @Transactional
    @Override
    public void add(Role role) {
        mapper.add(role);
    }
    @Transactional
    @Override
    public void update(Role role) {
        mapper.update(role);
    }
    @Transactional
    @Override
    public void delete(Integer id) {
        mapper.delete(id);
    }
}
